<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="省份地区" prop="area">
                <el-input v-model="queryParams.area" placeholder="请输入省份地区"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="批次名称" prop="name">
              <el-input v-model="queryParams.name" placeholder="请输入批次名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="购买标包" prop="biaobao">
              <el-input v-model="queryParams.biaobao" placeholder="请输入购买标包"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="开标时间" prop="openDate">
                <el-date-picker clearable v-model="queryParams.openDate"
                                type="date" value-format="yyyy-MM-dd" placeholder="请选择开标时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="是否中标" prop="isWin">
                <el-input v-model="queryParams.isWin" placeholder="请输入是否中标"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="中标时间" prop="winDate">
              <el-date-picker clearable v-model="queryParams.winDate"
                              type="date" value-format="yyyy-MM-dd" placeholder="请选择中标时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="中标类别" prop="winType">
              <el-input v-model="queryParams.winType" placeholder="请输入中标类别"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
           <el-form-item label="保证金描述" prop="bondReamrk">
              <el-input v-model="queryParams.bondReamrk" placeholder="请输入保证金描述"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          <!-- <el-form-item label="中标金额描述" prop="winRemark">
              <el-input v-model="queryParams.winRemark" placeholder="请输入中标金额描述"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="中标服务费描述" prop="serviceRemark">
              <el-input v-model="queryParams.serviceRemark" placeholder="请输入中标服务费描述"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>-->
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['develop:LnZhaobiao:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button type="info" icon="el-icon-upload2" size="mini"
                         @click="daoruZhaobiao"  v-hasPermi="['develop:LnZhaobiao:export']">导入招标信息</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini"
                        @click="handleExport" v-hasPermi="['develop:LnZhaobiao:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight" @sort-change="handleSortChange" show-summary :summary-method="getSummaries">
            <!--<el-table-column type="selection" width="55" align="center"/>-->
            <el-table-column sortable label="省份地区" align="center" prop="area"/>
            <el-table-column sortable label="批次名称" align="center" prop="name" show-overflow-tooltip />
            <el-table-column sortable label="购买标包" align="center" prop="biaobao" show-overflow-tooltip />
            <el-table-column label="特殊要求或不满足记录" align="center" prop="other" show-overflow-tooltip >
                <template slot-scope="scope">
                    <span  style="color: blue;">{{ scope.row.other }}</span>
                </template>
            </el-table-column>
            <el-table-column sortable label="开标时间" align="center" prop="openDate" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.openDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>
           <!-- <el-table-column label="开标描述" align="center" prop="openRemark"/>-->
            <el-table-column sortable label="保证金金额(万元)" align="center" prop="bond"/>
            <el-table-column label="保证金描述" align="center" prop="bondReamrk"/>
            <el-table-column sortable label="是否中标" align="center" prop="isWin"/>
            <!-- <el-table-column sortable label="中标金额(万元)" align="center" prop="winMoney"/>
            <el-table-column label="标书制作" align="center" prop="doBook"/> -->
            <!-- <el-table-column sortable label="中标类别" align="center" prop="winType"/>
            <el-table-column sortable label="中标时间" align="center" prop="winDate" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.winDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
              </template>
            </el-table-column>
            <el-table-column sortable label="中标服务费(万元)" align="center" prop="winService"/>
            <el-table-column sortable label="中标服务费状态" align="center" prop="serviceStatus"/> -->
            <el-table-column label="备注" align="center" prop="remark"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit"
                            @click="handleUpdate(scope.row)" v-hasPermi="['develop:LnZhaobiao:edit']">修改</el-button>
                    <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                   style="margin-left: 10px;">
                        <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                   v-hasPermi="['develop:LnZhaobiao:remove']">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

        <lnZhaobiao-form ref="form" @ok="getList"></lnZhaobiao-form>
        <upload-dialog ref="uploadDialog" @ok="getList" @handleFileSuccess="handleFileSuccess"></upload-dialog>
    </div>
</template>

<script>
    import { deleteAction, getAction ,downloadFile,accAdd} from '@/api/manage'
    import LnZhaobiaoForm from '@/views/develop/lnZhaobiao/module/LnZhaobiaoForm'
    import UploadDialog from "@/views/upload/UploadDialog";

    export default {
        name: "LnZhaobiaoList",
        components: {
            LnZhaobiaoForm,
            UploadDialog,
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 招标信息表格数据
                dataList: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    name: null,
                    code: null,
                    status: null,
                    type: null,
                    area: null,
                    biaobao: null,
                    other: null,
                    openDate: null,
                    openRemark: null,
                    bond: null,
                    bondReamrk: null,
                    isWin: null,
                    winMoney: null,
                    winRemark: null,
                    doBook: null,
                    winType: null,
                    winService: null,
                    serviceRemark: null,
                    serviceStatus: null,
                    winDate: null,
                    orderByColumn: 'open_date',
                    isAsc: "desc"
                },
                url: {
                    list:'/lnZhaobiao/lnZhaobiao/list',
                    remove:'/lnZhaobiao/lnZhaobiao/',
                    export:'/lnZhaobiao/lnZhaobiao/export',
                },
                tableMaxHeight: window.innerHeight - 320,
            };
        },
        created() {
            this.getList();
            window.addEventListener('resize', this.getTableHeight);
        },
        destroyed () {
            window.removeEventListener('resize', this.getTableHeight)
        },
        methods: {
            getSummaries(param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                sums[index] = "合计";
                return;
                }
                const values = data.map((item) => Number(item[column.property]));
                // 只合计amount1和amount3，想合并哪些列就在这里指定
                if (column.property === "bond" || column.property === "winMoney" || column.property === "winService" ) {
                sums[index] = values.reduce((prev, curr) => {

                    const value = Number(curr);
                    if (!isNaN(value)) {
                    return accAdd(prev, curr);
                    } else {
                    return prev;
                    }
                }, 0);
                }
            });
            return sums;
            },
                    /** 排序触发事件 */
            handleSortChange(column, prop, order) {
            this.queryParams.orderByColumn = column.prop;
            this.queryParams.isAsc = column.order;
            this.handleQuery();
            },
            daoruZhaobiao(){
              this.$refs.uploadDialog.title = "招标信息导入";
              this.$refs.uploadDialog.tmplName = "招标信息.xlsx";
              this.$refs.uploadDialog.fileName = "招标信息模板.xlsx";
              this.$refs.uploadDialog.uploadUrl = "/lnZhaobiao/lnZhaobiao//importData";
              this.$refs.uploadDialog.show();
            },
            handleFileSuccess(response, file, fileList) {
              this.$refs.uploadDialog.open = false;
              this.$refs.uploadDialog.isUploading = false;
              if (response.data.code == "200") {
                this.$alert("导入数据：" + response.data.num + "条！更新数据：" + response.data.numupdate + "条！" + response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
              } else {
                this.$alert("导入数据：" + response.data.num + "条！更新数据：" + response.data.numupdate + "条！" + response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
              }
              this.getList();
          },
            /** 查询招标信息列表 */
            getList() {
                this.loading = true;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getTableHeight () {
                this.tableHeight = window.innerHeight - 320
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.remove, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
                this.download(this.url.export, {
                    ...this.queryParams
                }, `lnZhaobiao_${new Date().getTime()}.xlsx`)
            },
  }
};
</script>
